
JP Goodwin
|
Posted - 2008.06.24 08:41:00 -
[1]
Edited by: JP Goodwin on 24/06/2008 08:43:12 Another comment on UDP vs TCP.
I worked as a software developer on a network protocol stack for 5+ years back in the 90's. Our code ran on top of TCP, we weren't reinventing TCP. 90 to 95% of our code was error handling and recovery, with only 5-10% executed in the "normal" case. Some of that code was fiendishly difficult to debug due to multiple messages being handled at once and it being hard to reproduce the exact sequence of events even once you'd figured out what order things had happened in when they went wrong. Being able to do multithreaded programming with no logic holes and no memory leaks is a specialist skill that your average CS college grad is hopeless at when they first show up.
What TCP provides is "reliable, in-order delivery". That's its contract with the network layers above it. UDP does not provide reliable or in-order delivery. Yes you could implement on top of UDP instead of TCP, and build whatever kind of network layer you want. But if what you need is reliable delivery without packet reordering then you either use TCP or you reinvent the wheel. And trust me, running on a TCP reinvented by a bunch of game programmers is not what you want.
I played Diablo II for a good while back when it was hot and it was absolutely plagued with exploits. Item duplication exploits were the most common. Many (if not most) involved disconnecting from the game by one party involved in a trade at just the right point. Blizzard was basically hopeless at plugging all the holes. And although I didn't work there, I have an idea why. You see, they chose to implement on top of UDP. I used up quite a lot of emotional energy ranting at that choice back then.
The two advantages of UDP over TCP are that it is lighter weight and that it supports multicast (where you send the same packet from the server to lots of clients). That's particularly good for things like streaming video, where a lost packet is just a lost frame, a stutter that may even be invisible to the user. It's good for bit torrents, too. It's not so good for transaction type interactions (trading something with another player for example, or shooting them). If somebody somehow blew up one of the stars in Jita and they wanted to be able to show the same cut scene to everyone in Jita at the same time then multicast would be the only way to go. If you shot someone and they didn't get the message you'd be kind of unhappy, wouldn't you? Especially if they then shot back and that message didn't get lost.
Yes TCP is heavier weight, but if you need the features it provides, then its the lowest cost way to get those features, both in terms of performance and development costs.
True, with UDP you'd never get disconnected. But the game would be far less reliable overall.
|